import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 涛
 * Date: 2023-10-27
 * Time: 13:45
 */
class MyArray<T> {
    public T[] array = (T[])new Object[10];
    public T getPos(int pos) {
        return this.array[pos];
    }
    public void setVal(int pos, T val) {
        this.array[pos] = val;
    }
    public T[] getArray() {
        return this.array;
    }
}
public class Test {
    public static <E> void swap(E[] array, int i, int j) {
        E t = array[i];
        array[i] = array[j];
        array[j] = t;
    }
    public static void main(String[] args) {
        Integer[] array = {1,2,3,4,5};
        System.out.println(Arrays.toString(array));
        //不使用类推到
        Test.<Integer>swap(array, 0, 1);
        System.out.println(Arrays.toString(array));
        System.out.println("==============");
        //使用使用类推到
        swap(array, 0, 1);
        System.out.println(Arrays.toString(array));
    }
    public static void main2(String[] args) {
        MyArray<Integer> myArray = new MyArray<>();
        Integer[] array = myArray.getArray();
    }
    public static void main1(String[] args) {
        MyArray<Integer> myArray = new MyArray<>();
        myArray.setVal(0, 10);
        myArray.setVal(1, 20);
        int ret = myArray.getPos(0);
        System.out.println(ret);//输出10
    }
}
